package com.wymobilearchitecture.demo.kt


fun main() {
    fire(ApiGetArticles())
}

public enum class Method{
    GET,POST
}

@Target(AnnotationTarget.CLASS)//作用于类上
@Retention(AnnotationRetention.RUNTIME)//保留到运行时
public annotation class HttpMethod(val method : Method)

interface Api{
    val name : String
    val version : String get() = "1.0"
}

@HttpMethod(Method.GET)
class ApiGetArticles : Api{
    override val name : String get() = "/api.articles"
}

fun fire(api : Api){
    val annotations = api.javaClass.annotations
    val method : HttpMethod? = annotations.find { it is HttpMethod } as? HttpMethod//as 类型转换
    println("注解: ${method?.method}")
}